//
//  WJJCalendarLogic.m
//  HTTestPro
//
//  Created by JunWang on 16/3/9.
//  Copyright © 2016年 JunWang. All rights reserved.
//

#import "WJJCalendarLogic.h"

@implementation WJJCalendarLogic


+ (BOOL)isToday:(NSDateComponents *)day
{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    int unit = NSCalendarUnitDay | NSCalendarUnitMonth |  NSCalendarUnitYear;
    NSDateComponents *nowCmps = [calendar components:unit fromDate:[NSDate date]];
    if(day.year == nowCmps.year && day.month == nowCmps.month && day.day == nowCmps.day)
    {
        return true;
    }else{
        return false;
    }
}

+ (WJJFestivalType)checkFestival:(NSDateComponents *)day
{
    if (day.month == 1 &&
        day.day == 1){
        return WJJNewYearDay;
        //1.1元旦
    }else if (day.month == 3 &&
              day.day == 8){
        return WJJWomenDay;
        //3.8妇女节
    }else if (day.month == 4 &&
              day.day == 5){
        return WJJNewYearDay;
        //4.5清明节
    }else if (day.month == 5 &&
              day.day == 1){
        return WJJLaborDay;
        //5.1劳动节
    }else if (day.month == 5 &&
              day.day == 4){
        return WJJYouthDay;
        //5.4青年节
    }else if (day.month == 6 &&
              day.day == 1){
        return WJJChildrenDay;
        //6.1儿童节
    }else if (day.month == 7 &&
              day.day == 1){
        return WJJPartyBirthday;
        //7.1建党节
    }else if (day.month == 8 &&
              day.day == 1){
        return WJJArmyDay;
        //8.1建军节
    }else if (day.month == 9 &&
              day.day == 10){
        return WJJTeacherDay;
        //9.10教师节
    }else if (day.month == 10 &&
              day.day == 1){
        return WJJNationalDay;
        //10.1国庆节
    }else if (day.month == 11 &&
              day.day == 11){
        return WJJSingleDay;
        //11.11光棍节
    }else if (day.month == 3 &&
              day.day == 8){
        return WJJNewYearDay;}else{
            return WJJFestivalNone;
        }
}

+ (BOOL)needRest:(NSDateComponents *)day
{
    WJJFestivalType type = [self checkFestival:day];
    if (type == WJJFestivalNone) {
        return false;
    }else{
        switch (type) {
            case WJJNationalDay:
                return true;
                break;
            case WJJLaborDay:
                return true;
                break;
            case WJJNewYearDay:
                return true;
                break;
            case WJJQingMingFestival:
                return true;
                break;
            default:
                return false;
                break;
        }
    }
}


+ (BOOL)isNoOverlappedWithlastMonth:(NSDateComponents*)month {
    month = [month.calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday | NSCalendarUnitCalendar fromDate:month.date];
    return (month.weekday - month.calendar.firstWeekday == 0);
}


@end
